package com.wanhau.quartz;

import java.util.Date;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class MyJob implements Job {
	
	private String aa;
	private String bb;

	public String getAa() {
		return aa;
	}


	public void setAa(String aa) {
		this.aa = aa;
	}


	public String getBb() {
		return bb;
	}


	public void setBb(String bb) {
		this.bb = bb;
	}


	public void execute(JobExecutionContext context) throws JobExecutionException {
		/**
		 * 有三种方式接收存入的参数
		 * 1. 用全局变量JobExecutionContext获取JobDetail和Trigger, 然后获取dataMap, 可以取出相应的值
		 * 2. 用结合后的方法接收, 但是如果JobDetail和Trigger的name重复的话, 就只会接收Trigger的值
		 * 3. 定义变量, 然后用setter/getter方法, 自动获取, 但重名的话也会覆盖
		 * */
		System.out.println(context.getJobDetail().getKey().getGroup()+new Date());
		System.out.println(context.getJobDetail().getKey().getName()+new Date());
		System.out.println(context.getTrigger().getKey().getGroup()+new Date());
		System.out.println(context.getTrigger().getKey().getName()+new Date());
		System.out.println("====================");
		String JobString = context.getJobDetail().getJobDataMap().getString("aa");
		System.out.println("a:"+JobString);
		float bb = context.getJobDetail().getJobDataMap().getFloat("bb");
		System.out.println("bb:"+bb);
		
		String TriggerAa = context.getTrigger().getJobDataMap().getString("aa");
		System.out.println("aa:" + TriggerAa);
		float Tbb = context.getTrigger().getJobDataMap().getFloat("bbb");
		System.out.println("Tbb:"+Tbb);
		System.out.println("====================");
		
		JobDataMap mergedJobDataMap = context.getMergedJobDataMap();
		String string = mergedJobDataMap.getString("aa");
		System.out.println(string);
		float f = mergedJobDataMap.getFloat("bbb");
		float ff = mergedJobDataMap.getFloat("bb");
		System.out.println(f);
		System.out.println(ff);
		System.out.println("====================");
		System.out.println("gouzai:"+aa);
		System.out.println(bb);
	}

}
